﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MadLibrary.Math
{
    /// <summary>
    /// Holds inverse proportionality informations and calculates data.
    /// </summary>
    public class InverseProportionality
    {
        /// <summary>
        /// Gets or sets coeffictient of current proportionality.
        /// </summary>
        public double Coefficient { get; set; }

        /// <summary>
        /// Creates new InverseProportionality and sets coefficient to zero.
        /// </summary>
        public InverseProportionality()
        {
            this.Coefficient = 0;
        }

        /// <summary>
        /// Creates new inverse proportionality and sets coefficient to specified value.
        /// </summary>
        /// <param name="Coefficient">Specifies coefficient value for new proportionality.</param>
        public InverseProportionality(double Coefficient)
        {
            this.Coefficient = Coefficient;
        }

        /// <summary>
        /// Gets Y value from current inverse proportionality.
        /// </summary>
        /// <param name="X">Specifies X value for Y value calculation.</param>
        /// <returns>Y value of current proportionality.</returns>
        public double GetY(double X)
        {
            return this.Coefficient / X;
        }

        /// <summary>
        /// Gets X value from current inverse proportionality.
        /// </summary>
        /// <param name="Y">Specifies Y value for X value calculation.</param>
        /// <returns>Y value of current proportionality.</returns>
        public double GetX(double Y)
        {
            return this.Coefficient / Y;
        }

        /// <summary>
        /// Calculates coefficient from specified data.
        /// </summary>
        /// <param name="X">Specifies X value for coefficient calculation.</param>
        /// <param name="Y">Specifies Y value for coefficient calculation.</param>
        public void SetCoefficient(double X, double Y)
        {
            this.Coefficient = X * Y;
        }

        /// <summary>Calculates coefficient from specified data.</summary>
        /// <param name="X">Specifies X value for coefficient calculation.</param>
        /// <param name="Y">Specifies Y value for coefficient calculation.</param>
        /// <returns>Calculated coefficient.</returns>
        public static double GetCoefficient(double X, double Y)
        {
            return X * Y;
        }

        /// <summary>
        /// Calculates X value from specified data.
        /// </summary>
        /// <param name="Coefficient">Specifies coefficient for X value calculation.</param>
        /// <param name="Y">Specifies Y value for X value calculation.</param>
        /// <returns>Calculated X value.</returns>
        public static double GetX(double Coefficient, double Y)
        {
            return Coefficient / Y;
        }

        /// <summary>Calculates Y value from specified data.</summary>
        /// <param name="Coefficient">Specifies coefficient for Y value calculation.</param>
        /// <param name="X">Specifies X value for Y value calculation.</param>
        /// <returns>Calculated Y value.</returns>
        public static double GetY(double Coefficient, double X)
        {
            return Coefficient / X;
        }
    }
}